package com.zz.retryall.transport;

import com.zz.retryall.exception.HelloRetryException;
import com.zz.retryall.service.IHelloService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.time.LocalTime;
import java.util.concurrent.atomic.AtomicInteger;

@Component
@Slf4j
public class HelloTransport implements IHelloService {

    public static AtomicInteger helloTimes = new AtomicInteger();

    @Override
    public String hello() {
        long times = helloTimes.incrementAndGet();
        if (times % 4 != 0){
            log.warn("发生异常，time：{}", LocalTime.now() );
            throw new HelloRetryException("发生Hello异常");
        }
        return "hello";
    }

}
